package com.zm.xdata.service.publics.poster.service.impl;

import com.zm.xdata.service.publics.poster.config.UPloadConfig;
import com.zm.xdata.service.publics.poster.Thirdparty.FileUpload.Service.IEsFileUploadService;
import com.zm.xdata.service.publics.poster.model.SysHaibao;
import com.zm.xdata.service.publics.poster.entity.SysHaibaoMapper;
import com.zm.xdata.service.publics.poster.service.ISysHaibaoService;
import com.zm.xdata.service.publics.poster.util.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 大鹏
 * @since 2022-05-26
 */
@Service
public class SysHaibaoServiceImpl extends ServiceImpl<SysHaibaoMapper, SysHaibao> implements ISysHaibaoService {

    @Autowired
    private IEsFileUploadService fileUploadService;

    @Autowired
    private UPloadConfig config;

    @Override
    public void upload(String name, MultipartFile touxiang, MultipartFile beijing) {
        if(StringUtils.isEmpty(name))
            throw new NullPointerException("名称不能为空");
        if(null == touxiang)
            throw new NullPointerException("头像不能为空");
        if(null == beijing)
            throw new NullPointerException("背景不能为空");
        //上传
        SysHaibao haibao=new SysHaibao();
        haibao.setName(name);
        haibao.setTouxiang(fileUploadService.save(touxiang,config.getImages()));
        haibao.setBeijing(fileUploadService.save(beijing,config.getImages()));
        save(haibao);
    }
}
